import { makeAutoObservable } from 'mobx'
import { userGetInfo, userLogin } from '@/api/login'
import { createStorage } from '@/utils/Storage';
const Storage = createStorage({ storage: localStorage });
import { storage } from '@/utils/Storage';
interface UserMobx {
  info:any;
  token:string;
}
const ex = 7 * 24 * 60 * 60 * 1000;
class User implements UserMobx{

  info = Storage.get("user","")
  token = Storage.get("token","")

  constructor() {
    makeAutoObservable(this)
  }

  async getLogin({username,password}){
    const res = await userLogin({ user_name: username, password: password })

    this.token = res.data.result.token

    storage.set("token", res.data.result.token,ex);
    await this.getInfo()
    return true
  }

  async getInfo (){
    const info = await userGetInfo()
    storage.set("user", info,ex);
    this.info = info
    console.log(info)
  }


}
const userStores = new User()
export {userStores}
